package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.LsearchDao;
import com.zr.model.Employee;
import com.zr.util.JDBCUtil;

public class LsearchDaoImpl implements LsearchDao{

	@Override
	public Employee lsearchByEid(int eid) {
		Employee u = new Employee();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT employee.ename,department.dname,resign.reason,resign.opinion,resign.remark,resign.retime,resign.state ");
		sql.append(" FROM resign ");
		sql.append(" INNER JOIN employee ");
		sql.append(" ON employee.eid=resign.eid ");
		sql.append(" INNER JOIN department ");
		sql.append(" ON department.did = employee.did ");
		sql.append(" WHERE resign.eid=? ");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, eid);
			ResultSet rs=pst.executeQuery();
			if(rs.next()){
			u.setEname(rs.getString("ename"));
			u.setDepartment(rs.getString("dname"));
			u.setWcontent(rs.getString("reason"));
			u.setOpinion(rs.getString("opinion"));
			u.setRemake(rs.getString("remark"));
			u.setRetime(rs.getString("retime"));
			u.setState(rs.getString("state"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return u ;
	}


}
